<?php
/**
 * @copyright:Copyright (C) 2010-2014 LiZaoNet Inc. (http://www.lizaonet.com)
 * @license: http://www.lizaonet.com
 * @link:http://www.lizaonet.com
 * @since:File available since Release v1.0
 * @Created by Azrael
 * @User: Azrael
 * @Date: 2016/1/26
 * @Time: 16:02
 *
 */

namespace Home\Model;


use Think\Model;

class UserlistModel extends Model
{
    /**
     * 通过图鉴ID获取用户信息
     * @param $mid
     * @return mixed
     */
    public function getUserInfoByTujianMid($mid){
        $info = $this->where(array("userlist"=>$mid))->find();
        return $info;
    }

    /**
     * 获取用户组信息
     * @param $mid
     * @return mixed
     */
    public function getUserInfoGroupByMid($mid){
        $info = $this->field("a.adminid as adminidd,b.*")->alias("a")->join(array(" __ADMIN_GROUP__ b on a.adminid=b.adminid"),"left")->where(array("a.mid"=>$mid))->find();
        return $info;
    }

    public function getUserByMidFid($mid,$fid){
        $info = $this->where(array("mid"=>$mid,"fid"=>$fid))->find();
        return $info;
    }

    /**
     * 添加一个用户信息
     * @param $user
     * @return mixed
     */
    public function addUser($user){
        $id = $this->add($user);
        return $id;
    }

    /**
     * 统计被推荐的用户总数
     * @param $tuijianmid  推荐MID
     * @return int
     */
    public function getTotal($tuijianmid){
        $data = $this->field("count(mid) as totals")->where(array("tuijianmid"=>$tuijianmid))->find();
        if($data){
            return $data['totals'];
        }else{
            return 0;
        }
    }

}